home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bccapp.zip / INDEX.H < prev    next >
C/C++ Source or Header  |  1991-09-15  |  2KB  |  97 lines

  1. /*
  2.  *
  3.  * Database indexing system
  4.  *
  5.  * (C) 1990 Vision Software
  6.  *
  7.  * $Id: index.h 1.2001 91/04/25 15:06:44 pcalvin release $
  8.  *
  9.  * Comments:
  10.  *
  11.  * In general, this class will not be used by the General Public.  It
  12.  * provides string based searching of records in a database file.
  13.  * In addition, it will allow us to traverse a database in a logical
  14.  * order after records have been deleted/added etc..
  15.  *
  16.  * Bugs:
  17.  *
  18.  * None documented
  19.  *
  20.  */
  21. #if (!defined(__INDEX__))
  22. #define __INDEX__
  23.  
  24. #if (!defined(__ACCESS__))
  25. #include <access.h>
  26. #endif
  27.  
  28. /*
  29.  *
  30.  *    Index length.  The index key is set by DATABASE as
  31.  *    we are created
  32.  *
  33.  */
  34. STATIC CONST CCH cchIndexKeyMax = 255;
  35.  
  36. /*
  37.  *
  38.  * Index file format.  Basically the index is a disk-based binary tree.
  39.  *    Access takes care of the "Head" of the tree
  40.  *
  41.  *    I use two classes here in order to ease computation of the index
  42.  *    record sizes
  43.  *
  44.  *    record size = sizeof(ITREE) + cchIndex;
  45.  *
  46.  */
  47. struct ITREE : public INF
  48.     {
  49.     friend class INDEX;
  50. private:
  51.     REC rec;                            // Record number to access in DATABASE
  52.     REC recLeft;                    // Next record to the LEFT in the INDEX
  53.     REC recRight;                    // Next record to the RIGHT in the INDEX
  54.     REC recParent;                    // Parent of this Branch in INDEX
  55.     REC recNext;                    //    Next record of identical key
  56.     REC recPrevious;                // Previous record of identical key
  57.     };
  58.     
  59. struct IDX : public ITREE
  60.     {
  61.     friend class INDEX;
  62. private:
  63.     CHAR rgchKey[cchIndexKeyMax];
  64.     };
  65.  
  66. /*
  67.  *
  68.  * Database indexes.  File access is controlled by ACCESS.
  69.  *
  70.  */
  71. class INDEX : private ACCESS
  72.     {
  73. public:
  74.     INDEX(SZ sz,CCH cchKeyMac);
  75.     REC RecFromSz(SZ sz,CCH cch,BOOL fMatchIfClose);
  76.     REC RecCreateSz(SZ sz,CCH cch,REC recCreate);
  77.     REC RecFirst();
  78.     REC RecLast();
  79.     REC RecNext();
  80.     REC RecPrevious();
  81.     REC RecDelete();
  82.     ACCESS::FMark;
  83.     ACCESS::FGotoMark;
  84. private:
  85.     BOOL FLastInChain();
  86.     BOOL FFirstInChain();
  87.     REC RecCreateDuplicate(SZ sz,CCH cch,REC recCreated);
  88.     REC RecFromSzCchRecRec(SZ sz,CCH cch,REC recCreate,REC recParent);
  89.     REC RecDeleteRight(REC recOriginal,REC recParent,REC recRight,REC recLeft);
  90.     REC RecDeleteLeft(REC recOriginal,REC recParent,REC recRight,REC recLeft);
  91.     REC RecDeleteLeftLinear(REC recOriginal,REC recParent,REC recRight);
  92.     REC RecDeleteRightLinear(REC recOriginal,REC recParent,REC recLeft);
  93.     IDX idx;
  94.     };
  95.  
  96. #endif    /* !defined(__ACCESS__) */
  97.